<?php

defined('IN_IA') or exit('Access Denied');
$table='sms_template';
$dos = array('display', 'post', 'list', 'del');
$do = !empty($_GPC['do']) && in_array($do, $dos) ? $do : 'list';
$category=array(1=>'监测通知',2=>'拨款凭证',3=>'库款划拨');

if ($do == 'list') {
    $_W['page']['title'] = '管理短信模板 - 模板列表';
    $status=getGeneStatus();
    $keyword = trim($_GPC['keyword']);
    $wheresql = " WHERE 1 ";
    if (!empty($keyword)) {
        $wheresql .= " AND title LIKE '%{$keyword}%'";
        $_GET['keyword']= $_GPC['keyword'];
    }

    $pindex = max(1, intval($_GPC['page']));
    $psize = 20; //ORDER BY createtime DESC
    $list = pdo_fetchall("SELECT * FROM " . tablename($table) . $wheresql . '   LIMIT ' . ($pindex - 1) * $psize . ',' . $psize);
    $pager='';
    template('sms/template_list');
}
if ($do == 'post') {
    $_W['page']['title'] = '管理短信模板 - 增加模板';
    $id = intval($_GPC['id']);
    if (checksubmit('submit')) {
        $data = array(
            'title' => $_GPC['title'],
            'content' => $_GPC['content'],
            'category' => $_GPC['category'],
            'status'=> intval($_GPC['status'])
        );
        if (empty($id)) {
            $data['createtime'] = TIMESTAMP;
            pdo_insert($table, $data);
        } else {
            pdo_update($table, $data, array('id' => $id));
        }
        message('数据更新成功！', url('sms/template/list'), 'success');
    }
    if (!empty($id)) {
        $row = pdo_fetch("SELECT * FROM " . tablename('sms_template') . " WHERE   id = '{$id}'");
    }
    template('sms/template_post');
}
if ($do == 'del') {
    $id = intval($_GPC['id']);
    if($id>0){
        pdo_delete($table,array('id' => $id));
        message('数据删除成功！', url('sms/template/list'), 'success');
    }
}